package com.example.xiaodu.yuejian12.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.xiaodu.yuejian12.Activity.ActivityDetailActivity;
import com.example.xiaodu.yuejian12.Activity.MasterDetailActivity;
import com.example.xiaodu.yuejian12.Bean.ClubBean;
import com.example.xiaodu.yuejian12.Bean.MasterBean;
import com.example.xiaodu.yuejian12.Bean.ShowBean;
import com.example.xiaodu.yuejian12.MeIP;
import com.example.xiaodu.yuejian12.MyViewHolder.ItemViewHolder;
import com.example.xiaodu.yuejian12.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by xiaodu on 2018/10/11.
 */

public class MasterAdapter extends RecyclerView.Adapter {
    private List<MasterBean> masterBeanList;
    private MeIP ip=new MeIP();
    private String meIP=ip.getIP();

    public void setData(List<MasterBean> list){
        masterBeanList=list;
        notifyDataSetChanged();
    }

    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
        LayoutInflater inflater=LayoutInflater.from(parent.getContext());
        View itemView=inflater.inflate(R.layout.master_item,parent,false);
        ItemViewHolder viewHolder=new ItemViewHolder(itemView);
        return viewHolder;
    }

    public void onBindViewHolder(RecyclerView.ViewHolder holder ,int position){
        final ItemViewHolder viewHolder=(ItemViewHolder)holder;
        MasterBean MasterBean=masterBeanList.get(position);

        String mname=MasterBean.getMname();
        String mintro=MasterBean.getMintro();
        String pic=MasterBean.getMpic();


        viewHolder.mname.setText("大师姓名： "+mname);
        viewHolder.mintro.setText("大师简介： "+mintro);
        Picasso.with(viewHolder.imageView.getContext()).load(meIP+"/yuejian/public/static/master/"+pic).into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                int pos = viewHolder.getLayoutPosition();
                Intent intent = new Intent(v.getContext(), MasterDetailActivity.class);
                intent.putExtra("masterID", masterBeanList.get(pos).getMid());
                v.getContext().startActivity(intent);
            }
        });


    }

    public  int getItemCount(){
        if (masterBeanList!=null)
            return masterBeanList.size();
        else
            return 0;
    }


}
